<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        let name="allen";
        let gender="man";
        let age=26;
        let obj={
            name,
            skill(){
                console.log("足球");
            }
        }
        let obj1={
            gender
        }
        let obj2={
            age
        }
        let obj3=Object.assign(obj,obj1,obj2);
        console.log(obj);
        console.log(obj1);
        console.log(obj2);

        //实现对象的浅拷贝
        let obj4={
            name:"安陵容",
            age:18,
            gender:"女",
            hobbies:["跳舞","唱歌"]
        }
        let obj5=Object.assign({},obj4);
        console.log(obj4);
        console.log(obj5);
        obj4.name="祺贵人";
        console.log(obj4);
        console.log(obj5);
        //对象属性不会相互影响

        obj4.hobbies[0]="调香";
        console.log(obj4);
        console.log(obj5);
        //这属于深层内容 表层拷贝就无法解决问题了

        //keys   属性名
        console.log(Object.keys(obj4));
        //values  属性值
        console.log(Object.values(obj4));

        let obj6={
            grade:"九年级",
            teacher:"张老师",
            subject:"数学"
        }

        //将对象压缩成字符串
        let jsonStr=JSON.stringify(obj6);
        console.log(jsonStr);
        //将字符串解压为js数据
        let obj7=JSON.parse(jsonStr);
        console.log(obj7);


        //实现对象的深拷贝
        let obj8={
            name:"芈八子",
            age:20,
            home:"楚国",
            husband:["秦王","黄歇"]
        }
        let str=JSON.stringify(obj8);
        let obj88=JSON.parse(str);
        console.log(obj8,obj88);
        obj8.name="芈珠";
        console.log(obj8,obj88);
        obj8.husband[0]="义渠君";
        console.log(obj8,obj88);             
</script>
</body>
</html>